package umage.figures;

import static org.jhotdraw.draw.AttributeKeys.FONT_BOLD;

import java.awt.Rectangle;

import org.jhotdraw.draw.CreationTool;
import org.jhotdraw.draw.TextFigure;

@FigureInfo(name = "Interface Figure", icon = "InterfaceFigure.png", toolbar = "Figures", toolbarPriority = 0, tool = CreationTool.class)
public class InterfaceFigure extends ClassFigure {
	protected TextFigure interfaceHeader;
	private int _diameter;
	private int _centerX;
	private int _centerY;
	private Rectangle _interface;

	public InterfaceFigure() {
		super();
		interfaceHeader = new TextFigure("<<interface>>");
		interfaceHeader.setEditable(false);
		nameFigure.setText("Interface Name");
		updateList();
	}

	@Override
	protected void updateList() {
		if (interfaceHeader != null) {
			removeAllChildren();
			add(interfaceHeader);
			add(nameFigure);
			FONT_BOLD.set(nameFigure, true);
			add(new SeparatorLineFigure());
			add(fieldList);
			add(new SeparatorLineFigure());
			add(methodList);
		}
	}

	@Override
	public InterfaceFigure clone() {
		InterfaceFigure that = (InterfaceFigure) super.clone();
		that.interfaceHeader = interfaceHeader.clone();
		return that;
	}

	public void setCenter(int x, int y) {
		int minValue = _diameter / 2;
		if (x < minValue) {
			_centerX = minValue;
		} else {
			_centerX = x;
		}
		if (y < minValue) {
			_centerY = minValue;
		} else {
			_centerY = y;
		}
		_centerX = x;
		_centerY = y;
		_interface.setLocation(_centerX - minValue, _centerY - minValue);
	}

}